var app = getApp();
var request = app.request;
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    asklist:[],    //问答列表
    askdata:"",    //获取到的数据
    good_id:"",  
    content:"",    //提问内容  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    request.get('/api/user/ask_all', {
      data: { id: options.goods_id, type: 'brief' },
      failRollback: true,
      isShowLoading: false,
      success: function (res) {
        var result = res.data.result;
        // 提问时间
        for (var i in result) {   
          result[i].question.updatetime = util.format(result[i].question.createtime, 'yyyy-MM-dd hh:mm');      
        }
        // 更新时间
        for (var i in result) {
          for (var j in result[i].comment) {
            var length = result[i].comment.length;//评论数量
            result[i].comment[j].updatetime = util.format(result[i].comment[j].createtime, 'yyyy-MM-dd hh:mm');
          }
        }
        that.setData({ asklist: res.data.result, askdata: res.data, good_id: options.goods_id});
      }
    });
  },
  // textarea值
  bindEquipmentId: function (e) {
    this.setData({
      content: e.detail.value
    })
  },
  // 提问
  a:function(e){
    var that=this;
    if (!that.data.content) {
      app.showTextWarining("请输入提问标题");
      return false;
    }
    request.get('/api/user/askall_ask', {
      data: { goods_id: that.data.good_id, content: that.data.content },
      failRollback: true,
      isShowLoading: false,
      success: function (res) {
        app.showTextWarining("恭喜您，提问成功!");
        that.setData({
          content: "",
        })
      }
    });
  },


  // 问大家
  goaskinfo: function (e) {
    var goodsid = e.currentTarget.dataset.goodsid;
    var qid = e.currentTarget.dataset.qid;
    wx.navigateTo({
      url: '/pages/goods/goodinfo_askinfo/goodinfo_askinfo?goods_id=' + goodsid + '&qid=' + qid,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})